package com.hyjr.RxTask.rabbitmq;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

import com.hyjr.common.utils.PropertyUtil;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

/**
 * @program: rabbit-learn
 * @description: 连接工厂类
 * @author: 535504
 * @create: 2018-04-26 15:10
 **/
public class ConnectionUtil {

	private static Connection connection = null;

	public static Connection getConnection() {
		if (connection == null) {
			ConnectionFactory connectionFactory = new ConnectionFactory();
			connectionFactory.setHost(PropertyUtil.getPropety("rabbitmq", "rabbitmq_ip"));
			connectionFactory.setUsername(PropertyUtil.getPropety("rabbitmq", "rabbitmq_user_name"));
			connectionFactory.setPassword(PropertyUtil.getPropety("rabbitmq", "rabbitmq_password"));
			try {
				connection = connectionFactory.newConnection();
			} catch (IOException e) {
				e.printStackTrace();
			} catch (TimeoutException e) {
				e.printStackTrace();
			}
		}
		return connection;
	}

}
